// PCSettings.cpp
//

#include "PursuitCore.h"

PCORE_API void PCLoadSettings(PCSettings* settings)
{
	char* settingspath = PCGetSettingsFilePath();

	settings->modeno = GetPrivateProfileInt(TEXT("DirectX"), TEXT("modeno"), 0, settingspath);
	settings->fullscreen = GetPrivateProfileInt(TEXT("DirectX"), TEXT("fullscreen"), 0, settingspath);
	settings->adapterno = GetPrivateProfileInt(TEXT("DirectX"), TEXT("adapterno"), 0, settingspath);
	settings->devicetype = (D3DDEVTYPE)GetPrivateProfileInt(TEXT("DirectX"), TEXT("devicetype"), 1, settingspath);
	settings->multisampletype = (D3DMULTISAMPLE_TYPE)GetPrivateProfileInt(TEXT("DirectX"), TEXT("multisampletype"), 0, settingspath);
	settings->multisamplequality = GetPrivateProfileInt(TEXT("DirectX"), TEXT("multisamplequality"), 0, settingspath);
	settings->deviceflags = GetPrivateProfileInt(TEXT("DirectX"), TEXT("deviceflags"), 0, settingspath);
}

PCORE_API void PCSaveSettings(PCSettings settings)
{
	char* settingspath = PCGetSettingsFilePath();

	char fullscreen[16];
	char adapterno[16];
	char modeno[16];
	char devicetype[16];
	char multisampletype[16];
	char multisamplequality[16];
	char deviceflags[16];

	_itoa_s(settings.fullscreen, fullscreen, 16, 10);
	_itoa_s(settings.adapterno, adapterno, 16, 10);
	_itoa_s(settings.modeno, modeno, 16, 10);
	_itoa_s(settings.devicetype, devicetype, 16, 10);
	_itoa_s(settings.multisampletype, multisampletype, 16, 10);
	_itoa_s(settings.multisamplequality, multisamplequality, 16, 10);
	_itoa_s(settings.deviceflags, deviceflags, 16, 10);

	WritePrivateProfileString(TEXT("DirectX"), TEXT("fullscreen"), fullscreen, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("adapterno"), adapterno, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("modeno"), modeno, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("devicetype"), devicetype, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("multisampletype"), multisampletype, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("multisamplequality"), multisamplequality, settingspath);
	WritePrivateProfileString(TEXT("DirectX"), TEXT("deviceflags"), deviceflags, settingspath);
}

PCORE_API char* PCGetPursuitDriftPath(void)
{
	char fname[MAX_PATH];
	static char pddir[MAX_PATH];

	SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, fname);
	sprintf_s(pddir, MAX_PATH, "%s\\PursuitDrift", fname);

	return pddir;
}

PCORE_API char* PCGetSettingsFilePath(void)
{
	static char filename[MAX_PATH];
	char* pdpath;

	pdpath = PCGetPursuitDriftPath();

	sprintf_s(filename, MAX_PATH, "%s\\PursuitDrift.pdcfg", pdpath);

	return filename;
}